package com.example.controller.configuration;

import com.example.bean.configuration.*;
import com.example.bean.configuration.vo.PingGuJiBieGuanLiVo;
import com.example.bean.configuration.vo.ShouFeiBiaoZhunVo;
import com.example.service.configuration.ShouFeiBiaoZhunService;
import com.example.utils.Result;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@CrossOrigin
@RestController
@RequestMapping("/shoufeibiaozhun")
public class ShouFeiBiaoZhunController {
    @Autowired
    ShouFeiBiaoZhunService service;

    @GetMapping("/xiala")
    public Result xiala(){
        List<JiGou> list = service.xiala();
        Result r = new Result();
        r.setData(list);
        return r;
    }

    @PostMapping("/page")
    public PageInfo<ShouFeiBiaoZhun> page(@RequestBody ShouFeiBiaoZhunVo vo){
        return service.getpage(vo);
    }

    @PostMapping("/addsfbz")
    public Result addsfbz(@RequestBody ShouFeiBiaoZhun shouFeiBiaoZhun){
        System.out.println(shouFeiBiaoZhun);
        Integer flag = service.addsfbz(shouFeiBiaoZhun);
        Result result = new Result();
        if(flag > 0){
            result.ok();
        }else{
            result.fail("失败");
        }
        return result;
    }

    @GetMapping("/{aid}")
    public Result getById(@PathVariable String aid){
        ShouFeiBiaoZhun shouFeiBiaoZhun = service.getId(aid);
        Result result = new Result();
        if(shouFeiBiaoZhun != null){
            result.ok();
            result.setData(shouFeiBiaoZhun);
        }else {
            result.fail("失败");
        }
        return result;
    }

    @PostMapping("/updatesfbz")
    public Result update(@RequestBody ShouFeiBiaoZhun shouFeiBiaoZhun){
        System.out.println(shouFeiBiaoZhun);
        Integer flag = service.xiugai(shouFeiBiaoZhun);
        Result result = new Result();
        if(flag > 0){
            result.ok();
        }else{
            result.fail("失败");
        }
        return result;
    }

    //批量删除
    @PostMapping("/dels")
    public Result dels(@RequestBody List<String> ids){
        //删除
        Integer flag =  service.dels(ids);
        Result result = new Result();
        if(flag > 0){
            result.ok();
        }else {
            result.fail("失败");
        }
        return result;
    }

}
